<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>Title</title>
    <script type="text/javascript" src="../js/common/jquery-1.9.0-min.js"></script>
</head>
<body>
<form enctype="multipart/form-data" >
    <label>姓名</label><input type="text" name="name"/>
    <label>密码</label><input type="password" name="password"/>
    <label>上传图片</label>
    <input type="file" name="file" id="file"/>
    <input type="button" value="上传" id="upload"/>
    <img id="myimage"/>
</form>
<script>
    $("#upload").click(function(){
        var data = new FormData();
        data.append('file',document.getElementById("file").files[0]);
        $.ajax({
            type: 'POST',
            url: "/ossUpload1",
            contentType: false, //禁止设置请求类型
            processData: false, //禁止jquery对DAta数据的处理,默认会处理
            //禁止的原因是,FormData已经帮我们做了处理
            data: data,
            success:function(data) {
                var data = $.parseJSON(data);
                console.log(data+"---------"+data["pathInfo"]);
                var element = document.getElementById('myimage');
                element.src = data["pathInfo"];
            },
            error : function(data) {
               console.log("error");
            }

        });
    })
</script>
</body>
</html>